package service;

/**
 * @author yk
 * @version 1.0
 * @date 2021/2/26
 */
public class HttpProtocolUtil {

    /**
     * 得到http header200
     *
     * @param contextLength 上下文的长度
     * @return {@link String}
     */
    public static String getHttpHeader200(long contextLength){
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length: "+contextLength+" \n" +
                "\r\n";
    }

    /**
     * 得到http header404
     *
     * @return {@link String}
     */
    public static String getHttpHeader404(){
        String str404 = "<h1> 404 not found <h1/>";
        return "HTTP/1.1 404 NOT Found \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length: "+str404.getBytes().length+" \n" +
                "\r\n"+str404;
    }
}
